package com.blu.system.controller;

import com.blu.response.Result;
import com.blu.system.service.AliOssService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Api
@RestController
@CrossOrigin
public class AliOssController {

    @Autowired
    private AliOssService aliOssService;

    @ApiOperation("OSS上传文件")
    @PostMapping("/uploadImgFile")
    public Result upload(MultipartFile file){
        String success = aliOssService.upload(file);
        return Result.ok().data("url",success);
    }

    @ApiOperation("OSS删除文件")
    @PostMapping("/deleteImgFile")
    public Result delete(String file){
        try{
            String[] split = file.split(".com/");
            aliOssService.deleteFile(split[1]);
            return Result.ok();
        } catch (Exception e){
            return Result.error();
        }

    }

}
